<?php

namespace plugin\admin\app\model;

use plugin\admin\app\model\Base;

/**
 * @property integer $id (主键)
 * @property integer $user_id 用户ID
 * @property integer $level 等级
 * @property integer $recommend_count 推荐人数
 */
class UserRecommendTeam extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_user_recommend_teams';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    public static function add($userId, $recommendLevel, $count)
    {
        if (self::where('user_id', $userId)->where('level', $recommendLevel)->count() > 0) {
            self::where('user_id', $userId)->where('level', $recommendLevel)->increment('recommend_count', $count);
        } else {
            self::insert([
                'user_id' => $userId,
                'level' => $recommendLevel,
                'recommend_count' => $count
            ]);
        }
    }
    
}
